package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.Service.CheckGropService;
import com.itheima.comstant.MessageConstant;
import com.itheima.domain.CheckGroup;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/CheckGropController")
public class CheckGropController {


    @Reference
    private CheckGropService checkGropService;


    //添加项目组的方法
    @RequestMapping("/addCheckGrop")
    public Result addCheckGrop(@RequestBody CheckGroup checkGroup,Integer[] checkitemIds ){

        try{
            checkGropService.addCheckGrop(checkGroup,checkitemIds);
            return  new Result(true, MessageConstant.ADD_CHECKGROUP_SUCCESS);
        }catch(Exception e){
            e.printStackTrace();

            return new Result(false,MessageConstant.ADD_CHECKGROUP_FAIL);

        }

    }



    //分页展示检测组
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){

            PageResult pageResult=checkGropService.findPage(queryPageBean);
            return pageResult;

    }


    //编辑检测组回显数据
    @RequestMapping("/findByIdToEdit")
    public Result findByIdToEdit(int row){

        try{
            CheckGroup checkGroup=checkGropService.findByIdToEdit(row);
            return new Result(true,"回显数据成功！！",checkGroup);
        }catch(Exception e) {
            e.printStackTrace();
            return new Result(false, "回显数据失败");

        }

    }


    //获取回显的检测项复选框
    @RequestMapping("/findCheckBox")
    public List<Integer> findCheckBox(int row){

        List<Integer> list=checkGropService.findCheckBox(row);
        return list;

    }

    //添加编辑修改
    @RequestMapping("/editCheckGroup")
    public Result editCheckGroup(@RequestBody CheckGroup checkGroup,Integer[] checkitemIds){

        try{
            checkGropService.editCheckGroup(checkGroup,checkitemIds);
            return new Result(true,MessageConstant.EDIT_CHECKGROUP_SUCCESS);
        }catch(Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.EDIT_CHECKGROUP_FAIL);

        }







    }


    //删除对应id的检测组
    @RequestMapping("/deleteCheckGrop")
    public Result deleteCheckGrop(int row){
        try{
            checkGropService.deleteCheckGrop(row);
            return new Result(true,MessageConstant.DELETE_CHECKGROUP_SUCCESS);
        }catch(Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.DELETE_CHECKGROUP_FAIL);
        }


    }



}
